# next() 函数

# gen = (num for num in range(10))
# print(next(gen))
# print(next(gen))
# print(next(gen))
# print("++++")
# for num in gen:
#     print(num)

# for i in range(5):
#     print(next(gen))
# print("+++")
# for i in range(5):
#     print(next(gen))


# def func():
#     print("line 1")
#     yield
#     print("line 2")
#     yield
#     print("line 3")
#     yield
#     print("line 4")
#     yield
#     print("line 5")
#     yield
#
#
# if __name__ == '__main__':
#     gen = func()
#     next(gen)
#     next(gen)

# send()函数
def func():
    while True:
        num = yield
        print(num)


def calc():
    while True:
        r = yield
        result = 3.14 * r * r
        print(result)


def generator(num):
    print("num=", num)
    outer_num = yield num
    print("recv num = ", outer_num)
    sum_ = yield num + outer_num
    print("recv sum = ", sum_)


if __name__ == '__main__':
    # gen = func()
    # next(gen)
    # gen.send(1)
    # gen = calc()
    # next(gen)
    # gen.send(10)
    gen = generator(10)
    next(gen)
    gen.send(20)
